package com.example.communitypro.util;

import com.example.communitypro.mapper.UserActionsMapper;
import com.example.communitypro.mapper.UserLikesMapper;
import com.example.communitypro.mapper.UserReportMapper;
import com.example.communitypro.pojo.Post;
import com.example.communitypro.pojo.UserInformation;
import org.springframework.context.ApplicationContext;

import java.util.ArrayList;
import java.util.List;

public class ReportAndActionsUtil {

    public static List<Post> userReportPost(List<Post> posts, int user_no){
        ApplicationContext ctx = SpringUtil.getApplicationContext();
        UserReportMapper userReportMapper = (UserReportMapper) ctx.getBean("userReportMapper");
        List<Post> posts1 = userReportMapper.getPostReport(user_no);
        for (int i=0;i<posts.size();i++) {
            Post post = posts.get(i);
            for ( Post post1 : posts1 ){
                if (post.getPostNo().equals(post1.getPostNo())) {
                    posts.remove(i);
                    break;
                }
            }
        }
        return posts;
    }

    public static List<Post> userActions(List<Post> posts, int user_no){
        ApplicationContext ctx = SpringUtil.getApplicationContext();
        UserActionsMapper userActionsMapper = (UserActionsMapper) ctx.getBean("userActionsMapper");
        List<UserInformation> userInformations = userActionsMapper.getUserFollow(user_no,0);
        for (UserInformation userInformation : userInformations) {  //排除拉黑用户的帖子
            for (int i=0;i<posts.size();i++) {
                Post post = posts.get(i);
                if (post.getUserNo().equals(userInformation.getUserNo())){
                    posts.remove(i);
                    break;
                }
            }
        }
        return posts;
    }
}
